home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4811 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  63 lines

  1. Path: ias_ppp0139.iamerica.net!72274.264
  2. From: 72274.264@compuserve.com (Sergey Kurtsev)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Aborting Constructors
  5. Date: Wed, 31 Jan 1996 07:48:50 -0500
  6. Organization: Hello, all.
  7. Message-ID: <72274.264.57.001E55E1@compuserve.com>
  8. References: <4eoeck$t6n@news.ios.com>
  9. NNTP-Posting-Host: ias_ppp0139.iamerica.net
  10. X-Newsreader: Trumpet for Windows [Version 1.0 Rev B]
  11.  
  12. In article <4eoeck$t6n@news.ios.com> leonardj@tribeca.ios.com (John Leonard) writes:
  13.  
  14.  
  15.  <aborting constructors and stuff - skipped>
  16.  
  17.  
  18.   NOTE: All further ideas are of my own...
  19.         They were NOT tested !..
  20.  
  21.  
  22.   If you want to call a destructor directly inside of the constructor - you 
  23. can do this. But take into consideration next:
  24.  
  25.   1. If you class is refrenced as an allocated on the heap
  26.  
  27. //--------------
  28.       class A {};
  29.  
  30.      main()
  31.       {
  32.        A *onHeap;
  33.        onHeap=new A();
  34.       };
  35. //--------------
  36.  
  37.      but not as a variable of a class type
  38. //--------------
  39.       class A()
  40.  
  41.       main()
  42.        { 
  43.         A classVar();
  44.        };
  45. //--------------
  46.  
  47.       then you have to take care about deleting a class from the heap (in the 
  48. constructor or outside of it, in the place it was called from). If you do 
  49. delete it inside the constructor
  50.  
  51.     delete this;
  52.  
  53. than logically class is not considered to be valid any more - it just doesn't 
  54. exist. In the same time - if you don't use any vars after deleting - the code 
  55. should still be valid, i.e. it shouldn't cause any lock ups or smth like this.
  56.  
  57.  2. Destructor should never be called directly - but it doesn't cause any 
  58. problems also if you use it's calls with a care.
  59.  
  60.   Good luck,
  61.   Sergey.
  62.  
  63.